package battleroom;

import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.control.Control;


/**
 *
 * @author zach && adam
 * 
 * This class control the spatial for which a shot is related to. 
 * A bullet is NOT A PROJECTILE. A bullet happens instantly, right when
 * the user presses LMB. This controls the spatial that is created by that action
 * which will be removed after decayTime
 */
public class BaseBullet extends AbstractControl
{
    
    private Vector3f from, to; //from = where it was shot from(ie gun.getBulletPosition(), to = 
    private float decayTime;
    private float startTime;
    
    public BaseBullet(float decay, Vector3f from, Vector3f to)
    {
        decayTime = decay;
        this.from = from;
        this.to   = to;
        startTime = -1;
    }
    
    @Override
    protected void controlUpdate(float tpf) {
        if(getSpatial() != null)
        {
            if(startTime == -1 )
            {
                System.out.println("SET");
                startTime = 0;
            }else if(startTime >= decayTime){
                getSpatial().getParent().detachChild(getSpatial());
            }else{
                startTime += tpf;
            }
        }
        
        System.out.println("Result: " + ((float)System.currentTimeMillis() + " - " + startTime));
    }

    /*@Override
    public void setSpatial(Spatial spatial)
    {
        super.setSpatial(spatial);
        
                
    }*/
    
    @Override
    protected void controlRender(RenderManager rm, ViewPort vp) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public Control cloneForSpatial(Spatial spatial) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
        
}